PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Copy

The Copy command is an AppleScript command that makes a copy of one or more values and stores the result in one or more variables. For information on differences between the Copy command and the Set command, see Data Sharing. The Set command is described in Set.

To copy within an application, you should use the command Duplicate. To copy between applications, performing the equivalent of the Edit menu's Copy command, you typically use the Clipboard-related scripting addition commands that are part of AppleScript's Standard Additions. For information about the standard scripting addition commands distributed with AppleScript, see the AppleScript section of the Mac OS Help Center.

As shown in the syntax definition, put and into are synonyms for copy and to . When you compile a script, put and into are automatically changed to copy and to .

SYNTAX
( copy | put ) expression ( to | into) variablePattern
PARAMETERS
expression
The expression whose value is to be assigned. If expression is a reference or a list or record of references, AppleScript gets the values of the objects specified by the references. Class: Any class
variablePattern
The name of the variable in which to store the value, or a list of variable patterns, or a record of variable patterns. Class: Identifier, list, or record
RESULT

If the Copy command is used to assign a value to a variable, the result is the value that was stored in the variable. If the command is used to copy an object, the result is a reference to the copied object. Class: Varies

EXAMPLES

The following example copies a string to the variable myOccupation :

copy "writer" to myOccupation

The next example gets a reference to a window, copies it to another reference, then gets the window's name form the copied reference:

set windowRef to a reference to window 1 of application "Finder"
copy windowRef to currentWindow
name of currentWindow --result: "Script testing folder"

In addition to copying a value to a single variable or object, you can copy patterns of values to patterns of variables. For example, this script copies the position of the front window to a list of two variables:

tell application "Finder"
    copy position of front window to {x, y} --result: {13, 47}
end tell

Since the Finder returns position of front window as a list of two integers, the preceding example copies the first item in the list to x and the second item in the list to y .

Patterns copied with the Copy command can also be more complex. For example:

set x to {8, 94133, {firstName:"John", lastName:"Chapman"}}
copy x to {p, q, {lastName:r}}
return(p, q, r) --result: {8, 94133, "Chapman"}

As this example demonstrates, the properties of a record need not be given in the same order and need not all be used when you copy a pattern to a pattern, as long as the patterns match.

The use of the Copy command with patterns is similar to the use of the Set command with patterns. For information about the Set command, see Set.

NOTES

For more information about using the Copy command to create or change the values of variables, see Variables.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)